package com.cis.web.controller.education;

import java.util.List;

import com.cis.education.domain.EduClassroom;
import com.cis.education.service.IEduClassroomService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.cis.common.annotation.Log;
import com.cis.common.enums.BusinessType;
import com.cis.common.core.controller.BaseController;
import com.cis.common.core.domain.AjaxResult;
import com.cis.common.utils.poi.ExcelUtil;
import com.cis.common.core.page.TableDataInfo;

/**
 * 教室管理Controller
 * 
 * @author 管理员
 * @date 2022-01-11
 */
@Controller
@RequestMapping("/education/classroom")
public class EduClassroomController extends BaseController
{
    private String prefix = "education/classroom";

    @Autowired
    private IEduClassroomService eduClassroomService;

    @RequiresPermissions("education:classroom:view")
    @GetMapping()
    public String classroom()
    {
        return prefix + "/classroom";
    }

    /**
     * 查询教室管理列表
     */
    @RequiresPermissions("education:classroom:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EduClassroom eduClassroom)
    {
        startPage();
        List<EduClassroom> list = eduClassroomService.selectEduClassroomList(eduClassroom);
        return getDataTable(list);
    }

    /**
     * 导出教室管理列表
     */
    @RequiresPermissions("education:classroom:export")
    @Log(title = "教室管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EduClassroom eduClassroom)
    {
        List<EduClassroom> list = eduClassroomService.selectEduClassroomList(eduClassroom);
        ExcelUtil<EduClassroom> util = new ExcelUtil<EduClassroom>(EduClassroom.class);
        return util.exportExcel(list, "教室管理数据");
    }

    /**
     * 新增教室管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存教室管理
     */
    @RequiresPermissions("education:classroom:add")
    @Log(title = "教室管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EduClassroom eduClassroom)
    {
        return toAjax(eduClassroomService.insertEduClassroom(eduClassroom));
    }

    /**
     * 修改教室管理
     */
    @RequiresPermissions("education:classroom:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        EduClassroom eduClassroom = eduClassroomService.selectEduClassroomById(id);
        mmap.put("eduClassroom", eduClassroom);
        return prefix + "/edit";
    }

    /**
     * 修改保存教室管理
     */
    @RequiresPermissions("education:classroom:edit")
    @Log(title = "教室管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EduClassroom eduClassroom)
    {
        return toAjax(eduClassroomService.updateEduClassroom(eduClassroom));
    }

    /**
     * 删除教室管理
     */
    @RequiresPermissions("education:classroom:remove")
    @Log(title = "教室管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(eduClassroomService.deleteEduClassroomByIds(ids));
    }
}
